<?php
$loader->requireOnce('includes/LabConnector/ILabConnector.class.php');
$loader->requireOnce('includes/EnumerationConstant.class.php');
$loader->requireOnce('includes/PatientQueue/AbsQueue.class.php');
/**
 * Connector for lab module deal with outpatient.
 * @package include
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class OutpatientLabConnector implements ILabConnector {

    private $logger ;
    function __construct() {
        $this->logger = LoggerManager::getLogger('includes.LabConnector.OutpatientLabConnector');
    }
    /**
     * Action be called after an assignment is deleted.
     * @param $ticketId
     * @param $labAssignmentTicketId
     * @return unknown_type
     */
    public function doAfterAssignmentDeleted($ticketId, $labAssignmentTicketId) {
        $this->logger->info("Start doAfterAssignmentDeleted[" . $ticketId . "," . $labAssignmentTicketId . "]");
        $objTicketItem  =   ORDataObject::factory('TicketItem');
        $ticketItemId   =   $objTicketItem->getTicketItemId($labAssignmentTicketId, TicketItem::TEST_TYPE);
        $objTicketItem->delete($ticketItemId);
        $this->logger->info("Finish doAfterAssignmentDeleted[" . $ticketId . "," . $labAssignmentTicketId . "]");
    }
    /**
     * Action be called after an assignment is created.
     * @param $ticketId
     * @param $labAssignmentTicketId
     * @return unknown_type
     */
    public function doAfterAssignmentCreated($ticketId, $labAssignmentTicketId, $data = array()) {
        $this->logger->info("Start doAfterAssignmentCreated[" . $ticketId . "," . $labAssignmentTicketId . "]");
        //create ticket item.
        $inTicketItemObj = Celini::newOrdo('TicketItem');
        $paracliniqueConfigObj = Celini::newOrdo('ParacliniqueConfig');
        $paracliniqueConfig = $paracliniqueConfigObj->getParaclinicConfig(EnumerationConstant::PARACLINIC_LAB);
        $inTicketItemObj->addLabAssignmentItem($ticketId, $labAssignmentTicketId, $paracliniqueConfig['room_id'],
        $data['original_price'], $data['insurance_price'], $data['patient_price']);
        $this->logger->info("Finish doAfterAssignmentCreated[" . $ticketId . "," . $labAssignmentTicketId . "]");


    }

    /**
     * Action be called after an assignment is finished.
     * @param $ticketId
     * @param $labAssignmentTicketId
     * @param $data   =   array('original_price', 'insurance_price', 'patient_price');
     * @return unknown_type
     */
    function doAfterAssignmentFinished($ticketId, $labAssignmentTicketId, $data = array()) {
        $this->logger->info("Start doAfterAssignmentFinished[" . $ticketId . "," . $labAssignmentTicketId . "]");
        //create in_ticket_item
        $inTicketItemObject = Celini::newOrdo("TicketItem");
        $inTicketItemObject->updatePrices($labAssignmentTicketId, EnumerationConstant::PARACLINIC_LAB, $data);

        // Set status of the ticket item to closed
        $ticketItemId   =   $inTicketItemObject->getTicketItemId($labAssignmentTicketId, TicketItem::TEST_TYPE);
        $inTicketItemObject->changeStatus($ticketItemId, TicketItem::CLOSED);
        $inTicketItemObject->close($ticketItemId);
        $this->logger->info("Finish doAfterAssignmentFinished[" . $ticketId . "," . $labAssignmentTicketId . "]");

    }

    public function doWhileAssignmentProcessing($ticketId, $labAssignmentTicketId) {
    	$this->logger->info("Start doWhileAssignmentProcessing[" . $ticketId . "," . $labAssignmentTicketId . "]");
        //create in_ticket_item
        $inTicketItemObject = Celini::newOrdo("TicketItem");
        $ticketItemId = $inTicketItemObject->getTicketItemId($labAssignmentTicketId, EnumerationConstant::PARACLINIC_LAB);
        if ($ticketItemId != 0 ) {
            //AbsQueue::moveTicketItemToQueue($ticketItemId, AbsQueue::IN_PROGRESS);
            $inTicketItemObject->changeStatus($ticketItemId, TicketItem::IN_PROGRESS);
        }
        $this->logger->info("Finish doWhileAssignmentProcessing[" . $ticketId . "," . $labAssignmentTicketId . "]");

    }

    public function doAfterAssignmentCanceled($ticketId, $labAssignmentTicketId) {
        $this->logger->info("Start doWhileAssignmentProcessing[" . $ticketId . "," . $labAssignmentTicketId . "]");
        //create in_ticket_item
        $inTicketItemObject = Celini::newOrdo("TicketItem");
        $ticketItemId = $inTicketItemObject->getTicketItemId($labAssignmentTicketId, EnumerationConstant::PARACLINIC_LAB);
        if ($ticketItemId != 0 ) {
            //AbsQueue::moveTicketItemToQueue($ticketItemId, AbsQueue::ENCOUNTER);
            $inTicketItemObject->changeStatus($ticketItemId, TicketItem::OPEN);
        }
        $this->logger->info("Finish doWhileAssignmentProcessing[" . $ticketId . "," . $labAssignmentTicketId . "]");

    }

}
?>